package com.lgcns.android2;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;

public class TeamActivity extends Activity {

    private static final String[] PROJECTION = {
        Constants.TEAM_DESC,
        Constants.TEAM_ORGANIZATION,
        };

    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        
        setContentView(R.layout.team);

        Cursor cursor = managedQuery(ProfileProvider.TEAM_CONTENT_URI, PROJECTION, null, null, null);

        if (cursor.getCount() == 0) {
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Error");
            builder.setIcon(android.R.drawable.ic_dialog_alert);
            builder.setMessage("DB 데이터가 잘못되었습니다.\n\n프로그램을 종료합니다.");
            builder.setPositiveButton("확인", new OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    finish();
                }
            });
            builder.show();
        } else {
            cursor.moveToFirst();
            
            byte[] teamDesc = cursor.getBlob(cursor.getColumnIndex(Constants.TEAM_DESC));
            byte[] teamOrganization = cursor.getBlob(cursor.getColumnIndex(Constants.TEAM_ORGANIZATION));
    
            Bitmap teamDescBitmap = BitmapFactory.decodeByteArray(teamDesc, 0, teamDesc.length);
            Bitmap teamOrganizationBitmap = BitmapFactory.decodeByteArray(teamOrganization, 0, teamOrganization.length);
    
            ImageView teamDescView = (ImageView) findViewById(R.id.team_desc);
            ImageView teamOrgaizationView = (ImageView) findViewById(R.id.team_organization);
            
            teamDescView.setImageBitmap(teamDescBitmap);
            teamOrgaizationView.setImageBitmap(teamOrganizationBitmap);
        }
    }

}
